import { useState, useEffect } from 'react';
import Http  from '@/utils/http';

interface httpHook {
  url : string;
  method?: string;
  headers?: object;
  body?: object;
  watch?: (string|number)[];
}


export default function useHttpHook({
  url,
  method = 'post',
  headers = {},
  body = {},
  watch = [],
}:httpHook)  {
  const [result, setResult] = useState({});
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    Http({
      url,
      method,
      headers,
      body,
      setResult,
      setLoading,
    });
  }, watch);
  
  return [result, loading];
}

